<template>
  <div class="bg-content content">
    <div>
      <van-tabs
        class="item-list"
        swipe-threshold="7"
        :ellipsis="false"
        color="#07C6B4"
        title-active-color="#07C6B4"
        line-width="50"
        v-model="active"
        swipeable
        @click="onClick"
      >
        <van-tab
          class="item"
          :name="item.value"
          v-for="item in navlist"
          :title="item.name"
        >
        </van-tab>
      </van-tabs>
    </div>
    <div class="header">
      <div class="message" @click="diloage()">
        <div class="logo">
          <img src="../../../../assets/img/main/know.png" alt="" />
        </div>
        <div class="message-content">
          <p class="span-one">挂号须知</p>
          <p class="span-two">挂号前请阅读！</p>
        </div>
        <van-overlay :show="show" @click="show = false" :lock-scroll="false">
          <div class="wrapper" @click.stop>
            <div class="block" @click="doclose()">
              <div class="block-title">挂号须知</div>
              <div class="block-message">
                <div class="message-title" v-if="message">
                  {{ message }}
                </div>
                <div class="message-title" v-else>暂无挂号须知</div>
              </div>
            </div>
          </div>
        </van-overlay>
      </div>
      <div class="myDoctor" @click="goMydoctor()">
        <div class="doctor-img">
          <img src="../../../../assets/img/main/my.png" alt="" />
        </div>
        <div class="myDoctor-content">
          <div class="mydoctor-name">我的医生</div>
          <div class="fast">快速预约</div>
        </div>
      </div>
    </div>
    <div class="banner">
      <div class="banner-left">
        <ul>
          <li
            v-for="(item, index) in items"
            :key="item.index"
            :class="{ active: bgColor == item.bigDepartmentId }"
            @click="chageright(item, index)"
          >
            {{ item.bigDepartmentName }}
          </li>
        </ul>
      </div>
      <div class="banner-right">
        <ul>
          <li
            v-for="(itam, index) in rightkeshi"
            :key="index"
            @click="test(itam)"
          >
            <div class="banner-right-li">{{ itam.departmentName }}</div>
            <div class="arrow">></div>
          </li>
        </ul>
      </div>
    </div>
    <div class="jishuzhichi">技术支持：郑州丰泰思科通信技术有限公司</div>
  </div>
</template>
<script>
import { Search, Toast } from "vant";
import { TreeSelect } from "vant";
import { Overlay } from "vant";
import { Dialog } from "vant";
import {
  getYuanQuOrDeptApi,
  getGuaHaoXuZhitApi,
  loginByWxOpenidApi,
  keshinavApi,
  typekeshiApi
} from "@/service/api.js";
export default {
  // mixins: [mixin],

  name: "index",
  data() {
    return {
      type: "",
      bgColor: "",
      show: false,
      value: "",
      activeId: 1,
      activeIndex: 0,
      departmentId: "", //科室id
      departmentName: "", //科室名称
      hospitalId: "", //医院id
      apptoken: "",
      token: "",
      items: [],
      message: {},
      navlist: [],
      active: "",
      rightkeshi: []
    };
  },
  components: {},
  created() {
    window.localStorage.removeItem("doctorlist");
    this.type = this.$route.query.type;
    localStorage.getItem("apptoken"),
      (this.apptoken = JSON.parse(localStorage.getItem("apptoken"))),
      (this.hospitalId = JSON.parse(localStorage.getItem("hosid"))),
      localStorage.getItem("atoken"),
      (this.token = localStorage.getItem("token")),
      this.getselect();
    this.getmessage();
    this.getkeshinav();
  },

  methods: {
    onClick(name) {
      localStorage.setItem("active", this.active);
      typekeshiApi({
        hospid: this.hospitalId,
        deptBelongValue: name
      }).then(res => {
        if (res.data.list.length > 0) {
          this.items = res.data.list;
          this.bgColor = this.items[0].bigDepartmentId;
          localStorage.setItem("bgColor", this.bgColor);
          this.rightkeshi = this.items[0].smallDeptList;
        } else {
          Toast("该分类下暂无科室");
        }
      });
    },
    getkeshinav() {
      keshinavApi({}).then(res => {
        this.navlist = res.data.list;
      });
    },
    chageright(item, index) {
      this.bgColor = item.bigDepartmentId;
      localStorage.setItem("bgColor", this.bgColor);
      localStorage.setItem("active", this.active);
      this.rightkeshi = this.items[index].smallDeptList;
    },

    panduan() {},
    getmessage() {
      getGuaHaoXuZhitApi({
        apptoken: this.apptoken,
        // hospitalId: this.id,
        hospitalId: this.hospitalId
      }).then(res => {
        if (res.code == 4000) {
          //成功
          this.message = res.data.hospitalRules;
        } else if (res.code == 4001) {
          //失败
        }
      });
    },
    // 获取科室列表
    getselect() {
      getYuanQuOrDeptApi({
        apptoken: this.apptoken,
        // hospitalId: this.id,
        hospitalId: this.hospitalId
      }).then(res => {
        if (res.code == 4000) {
          //成功

          this.items = res.data.list;
          let bgColor = localStorage.getItem("bgColor");

          if (bgColor) {
            this.bgColor = bgColor;
            let obj = this.items.find(item => item.bigDepartmentId === bgColor);
            this.rightkeshi = obj.smallDeptList;
            let active = localStorage.getItem("active");
            if (active) {
              this.active = active;
              typekeshiApi({
                hospid: this.hospitalId,
                deptBelongValue: active
              }).then(res => {
                this.items = res.data.list;
                this.bgColor = bgColor;
                let obj = this.items.find(
                  item => item.bigDepartmentId === bgColor
                );
                this.rightkeshi = obj.smallDeptList;
              });
            }
          } else {
            this.bgColor = this.items[0].bigDepartmentId;
            this.rightkeshi = this.items[0].smallDeptList;
          }
        } else if (res.code == 4001) {
          //失败
        }
      });
    },

    // 打开弹窗
    diloage() {
      this.show = true;
    },
    // 关闭弹窗
    doclose() {
      this.show = false;
    },
    // 跳转我的医生
    goMydoctor() {
      let token = localStorage.getItem("token");
      if (token) {
        this.$router.push({
          name: "Sc_doctor"
        });
      } else {
        Dialog.confirm({
          title: "提示",
          message: "需前往登录页面完成登录"
        })
          .then(() => {
            this.$router.push({
              name: "login"
            });
            // on confirm
          })
          .catch(() => {
            // on cancel
          });
      }
    },
    //去搜索页面
    gosearch(val) {
      if (val) {
        var reg = /^\S+$/;
        var seamsg = "";
        if (!reg.test(val)) {
          seamsg = "所在医院不能带空格";
          Toast("内容不能有空格");
        }
        if (seamsg == "") {
          this.$router.push({
            name: "Page_search"
          });
          let key = JSON.stringify(val);
          localStorage.setItem("key", key);
        }
      } else {
        Toast("不能为空");
      }
    },
    // 跳转医生列表
    test(val) {
      let token = localStorage.getItem("token");
      // if (token) {
      this.departmentId = val.departmentId;
      let departmentId = JSON.stringify(this.departmentId);
      localStorage.setItem("departmentId", departmentId);
      if (val.notice) {
        Dialog.alert({
          title: "科室公告",
          message: val.notice
        }).then(() => {
          // on close
        });
      }
      this.$router.push({
        name: "choose_doctor",
        query: {
          departmentName: this.departmentName,
          departmentId: this.departmentId
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.banner {
  display: flex;

  .banner-left {
    // margin-right: 0.2rem;
    height: 66vh;
    overflow: auto;
    // background-color: red;
    ul {
      overflow: auto;
      overflow-y: auto;
      li {
        width: 3.5rem;
        height: 1rem;
        padding: 0.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
        line-height: 1rem;
        font-size: 0.4rem;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #6c6c6c;
      }
      .active {
        background: #ffffff;
        color: #07c6b4;
      }
    }
  }
  .banner-right {
    width: 6.6rem;
    height: 66vh;
    overflow: auto;
    background: #ffffff;

    ul {
      overflow: auto;
      overflow-y: auto;
      li {
        display: flex;
        justify-content: space-between;
        font-size: 0.4rem;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #333333;
        white-space: nowrap;
        text-overflow: ellipsis;
        height: 1rem;
        line-height: 1rem;
        margin-left: 0.1rem;
        padding: 0.1rem;
        .banner-right-li {
          width: 5rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .arrow {
          // margin-right: 26px;
        }
      }
    }
  }
}
.bt {
  width: 200px;
  height: 50px;
  background-color: darkcyan;
  border-radius: 10px;
  margin-top: 10px;
  margin: 0 auto;
  text-align: center;
  line-height: 50px;
}
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 85%;
  height: 80%;
  background-color: #fff;
  overflow: auto;
  border-radius: 0.1rem;
  .block-title {
    font-size: 0.5rem;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    line-height: 0.6rem;
    text-align: center;
    margin-top: 0.3rem;
    margin-bottom: 0.2rem;
  }
  .block-message {
    .message-title {
      font-size: 0.4rem;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      line-height: 0.6rem;
      margin-left: 0.3rem;
      margin-right: 0.3rem;
      margin-bottom: 0.2rem;
    }
    .title {
      font-size: 0.3rem;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      line-height: 0.5rem;
      margin-left: 0.3rem;
      margin-right: 0.3rem;
      margin-bottom: 0.2rem;
    }
  }
}
.bg-content {
  width: 100%;
  // height: 100%;
  // height: 100vh;
  background: #f6f6f6;
  .jishuzhichi {
    position: fixed;
    width: 100%;
    bottom: 5px;
    text-align: center;
    margin-top: 80px;
    font-size: 12px;
    color: #999;
  }
  // overflow: auto;
  .header {
    width: 100%;
    height: 1.5rem;
    background-color: #ffffff;
    display: flex;
    justify-content: space-between;
    padding-bottom: 0.3rem;
    margin-bottom: 0.2rem;
    padding-top: 0.2rem;
    .message {
      display: flex;
      margin-top: 0.2rem;
      padding-left: 0.8rem;
      .logo {
        width: 1.2rem;
        height: 1.2rem;
        border-radius: 50%;
        margin-right: 0.2rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .message-content {
        .span-one {
          font-size: 0.35rem;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #333333;
          margin-top: 0.15rem;
        }
        .span-two {
          font-size: 0.3rem;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #999999;
        }
      }
    }
    .myDoctor {
      display: flex;
      margin-top: 0.2rem;
      padding-right: 1rem;
      .doctor-img {
        width: 1.2rem;
        height: 1.2rem;
        border-radius: 50%;
        margin-right: 0.2rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .mydoctor-name {
        font-size: 0.35rem;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #333333;
        margin-top: 0.15rem;
      }
      .fast {
        font-size: 0.3rem;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #999999;
      }
    }
  }
  .banner {
    width: 100%;
    .select {
      width: 100%;
      height: 100vh !important;
    }
  }
}
</style>
